package com.server.service.impl;

import com.common.bean.User;
import com.common.service.UserService;
import com.server.annotation.RpcBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author Zixiang Hu
 * @description
 * @create 2021-01-21-10:21
 */
@Slf4j
@RpcBean
public class UserServiceImpl implements UserService {
    /**
     * 模拟根据id获取
     *
     * @param id
     * @return
     */
    @Override
    public User getUserByUserId(Integer id) {
        log.info("客户端查询了id为{}的用户", id);
        // 模拟从数据库中取用户的行为
        User user = User.builder().name(UUID.randomUUID().toString())
                .id(id)
                .build();
        return user;
    }

    /**
     * 模拟插入
     *
     * @param user
     * @return
     */
    @Override
    public Integer insertUserId(User user) {
        log.info("数据插入成功，user = {}", user);
        return user.getId();
    }
}
